#include <stdio.h>
#include "string.h"

// 声明一个结构体类型 struct Date
struct Date {
    int year;  // 年
    int month; // 月
    int day;   // 日
};

struct Student {
    int num;              // 学号为整型
    char name[20];        // 姓名为字符串
    char sex;             // 性别为字符型
    int age;              // 年龄为整型
    float score;          // 成绩为实型
    struct Date birthday; // 出生日期
};

void printStudent(struct Student stu) {
    printf("学号：%d", stu.num);
    printf("，姓名：%s", stu.name);
    printf("，性别：%c", stu.sex);
    printf("，年龄：%d", stu.age);
    printf("，成绩：%.1f", stu.score);
    printf("，出生日期：%d-%d-%d\n",
           stu.birthday.year, stu.birthday.month, stu.birthday.day);
}

int main() {
    // 1. 定义结构体变量stu1, 初始化
    struct Student stu1 = {101, "Li Ming", 'M', 18, 90.5, {2000, 9, 10}};
    printStudent(stu1);
    // stu1 = {101, "Li Ming", 'M', 18, 90.5, {2000, 9, 10}};

    // 2. 定义结构体变量stu2, 赋值
    struct Student stu2;
    stu2.num = 102;
    // 字符串赋值不能用stu2.name = "Zhang Hong";
    strcpy(stu2.name, "Zhang Hong"); 
    stu2.sex = 'F';
    stu2.age = 19;
    stu2.score = 89.5;
    stu2.birthday.year = 1999;
    stu2.birthday.month = 8;
    stu2.birthday.day = 20;
    printStudent(stu2);

    // 3. 定义结构体变量stu3, 通过键盘输入值
    struct Student stu3;
    printf("请输入学号：");
    scanf("%d", &stu3.num);
    printf("请输入姓名：");
    scanf("%s", stu3.name);
    printf("请输入性别：");
    scanf(" %c", &stu3.sex);
    printf("请输入年龄：");
    scanf("%d", &stu3.age);
    printf("请输入成绩：");
    scanf("%f", &stu3.score);
    printf("请输入出生日期(年 月 日)：");
    scanf("%d %d %d", &stu3.birthday.year, &stu3.birthday.month, &stu3.birthday.day);
    printStudent(stu3);

    // 4. 定义结构体变量stu4, 结构体变量整体赋值
    struct Student stu4;
    stu4 = stu1;
    printStudent(stu4);

    return 0;
}